<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="layui/common/commonHead :: commonHead(~{::title},~{},~{})">
    <title>修改资源 EDIT</title>
</head>
<body>

<div class="layui-form"  lay-filter="userAdmin" id="userAdmin" style="padding: 20px 0 0 0;">
    <input type="hidden" name="id" th:value="${res.id}">
    <input type="hidden" name="parentId" value="0"  th:if="${res.parentId == 0}">
    <div class="layui-form-item"  th:if="${res.parentId != 0}">
        <label class="layui-form-label">父资源名称</label>
        <div class="layui-input-inline">
            <input type="text" name="parentId" id="parentNameSelect" lay-filter="parentNameSelect" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" th:value="${res.name}" lay-verify="required" placeholder="请输入资源名称(必填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" title="菜单"  th:checked="${res.type == '1'}">
            <input type="radio" name="type" value="2" title="按钮"  th:checked="${res.type == '2'}">
            <input type="radio" name="type" value="3" title="接口"  th:checked="${res.type == '3'}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源URL</label>
        <div class="layui-input-inline">
            <input type="text" name="resUrl" th:value="${res.resUrl}" lay-verify="required"  placeholder="请输入资源URL(必填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单URL</label>
        <div class="layui-input-inline">
            <input type="text" name="menuUrl"  th:value="${res.menuUrl}" placeholder="请输入菜单URL(选填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内部链接</label>
        <div class="layui-input-block">
            <input type="radio" name="classify" value="1" title="是"  th:checked="${res.classify == 1}">
            <input type="radio" name="classify" value="2" title="否"  th:checked="${res.classify == 2}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">打开新窗口</label>
        <div class="layui-input-block">
            <input type="radio" name="target" value="1" title="是"  th:checked="${res.target == 1}">
            <input type="radio" name="target" value="2" title="否"  th:checked="${res.target == 2}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="正常" th:checked="${res.status == 1}">
            <input type="radio" name="status" value="2" title="锁定" th:checked="${res.status == 2}"}>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input class="layui-btn layui-btn-normal" type="button" lay-submit lay-filter="add" id="id-sys-res-add-submit" value="保存">
            <input class="layui-btn layui-btn-primary" onclick="layerClose()" type="button"  lay-filter="close" id="id-sys-user-add-" value="取消">
        </div>
    </div>
</div>

<div th:replace="layui/common/commonJs :: commonJs(~{})"></div>
<script>
    layui.use(['index', 'form', 'upload',"treeSelect",'table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,treeSelect = layui.treeSelect;
        //监听锁定操作
        form.on('submit(add)', function(data){
            var field = data.field;
            //提交 Ajax 成功后，静态更新表格中的数据
            $.post('/sso/admin/menu/save', field, function (data, status) {
                if (data.status == 200) {
                    parent.layer.msg("修改成功");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
//                    parent.layui.table.reload("resources_list_table");
                    parent.layui.treeGrid.reload("menu_list_table");
                } else {
                    parent.layer.msg("修改失败请重试");
                }
            })
        });
        var parentId = [[${res.parentId}]];
        if(parentId != 0) {
            treeSelect.render({
                // 选择器
                elem: '#parentNameSelect',
                // 数据
                data: '/sso/admin/menu/treeSelectList',
                type: 'get',
                // 占位符
                placeholder: '请选择父资源名称',
                // 是否开启搜索功能：true/false，默认false
                search: true,
                style: {
                    folder: {
                        enable: false
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调
                click: function (d) {
                },
                // 加载完成后的回调函数
                success: function (d) {
//                选中节点，根据id筛选
                    treeSelect.checkNode('parentNameSelect', parentId);
//                获取zTree对象，可以调用zTree方法
//                var treeObj = treeSelect.zTree('tree');
//                console.log(treeObj);

//                刷新树结构
//                treeSelect.refresh('tree');
                }
            });
        }
    });
    function layerClose() {
        layui.use(['layer' ], function() {
            var layer = layui.layer;
            var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
            parent.layer.close(index);//关闭弹出层
        })
    }
</script>
</body>
</html>